package com.ad.pet.app.account.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.models.remote.account.order.BigOrder;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * 商城订单item
 * Created by SEELE on 2019/2/14.
 */

public class OrderStatusAdapter extends BaseQuickAdapter<BigOrder, BaseViewHolder> {
    private OnItemClickLinstener mOnItemClickLinstener;

    public OrderStatusAdapter(@Nullable List<BigOrder> data) {
        super(R.layout.item_status_good_layout, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final BigOrder item) {

        TextView tv_title = helper.getView(R.id.tv_title);
        TextView tv_create = helper.getView(R.id.tv_status);
        RecyclerView recycler_good = helper.getView(R.id.recycler_good);
        TextView tv_left = helper.getView(R.id.tv_left);
        TextView tv_right = helper.getView(R.id.tv_right);
        TextView tvCount = helper.getView(R.id.tv_count);
        tvCount.setText("合计:￥"+item.getOrder_money());
//        if ("4".equals(item.getOrder_status())) {
//            helper.getView(R.id.relativeLayout_reduce).setVisibility(View.GONE);
//        } else {
//            helper.getView(R.id.relativeLayout_reduce).setVisibility(View.VISIBLE);
//        }
//
        //订单状态 0:待付款 1:待发货 2:已发货 3:已收货 4:已完成 5:已关闭 -1:退款中

        switch (item.getOrder_status()){
            case "0":
                tv_left.setVisibility(View.VISIBLE);
                tv_right.setVisibility(View.VISIBLE);
                tv_right.setText("立即付款");
                tv_create.setText("待付款");
                tv_left.setText("取消订单");
                tv_create.setTextColor(mContext.getResources().getColor(R.color.red3c));
                break;
            case "1":
                tv_left.setVisibility(View.GONE);
                tv_right.setVisibility(View.GONE);
                tv_create.setText("买家已付款");
                tv_create.setTextColor(mContext.getResources().getColor(R.color.red3c));
                break;
            case "2":
                tv_left.setVisibility(View.VISIBLE);
                tv_right.setVisibility(View.VISIBLE);
                tv_create.setText("商家已发货");
                tv_create.setTextColor(mContext.getResources().getColor(R.color.red3c));
                tv_left.setText("查看物流");
                tv_left.setVisibility(View.GONE);
                tv_right.setText("确认收货");
                break;
            case "4":
                tv_left.setVisibility(View.VISIBLE);
                tv_right.setVisibility(View.GONE);
                tv_left.setText("查看物流");
                tv_left.setVisibility(View.GONE);
                tv_create.setText("交易成功");
                tv_create.setTextColor(mContext.getResources().getColor(R.color.grey_ac));
                break;
            case "5":
                tv_left.setVisibility(View.GONE);
                tv_right.setVisibility(View.GONE);
                tv_create.setText("已关闭");
                tv_create.setTextColor(mContext.getResources().getColor(R.color.grey_ac));
                break;
            case "-1":
                break;
        }
        tv_title.setText(item.getShop_name());
        OrderGoodAdapter orderGoodAdapter = new OrderGoodAdapter(item.getOrder_goods_list());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        recycler_good.setLayoutManager(linearLayoutManager);
        recycler_good.setAdapter(orderGoodAdapter);

        tv_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLinstener.onCancel(helper.getLayoutPosition());
            }
        });

        tv_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLinstener.onConfirm(helper.getLayoutPosition());
            }
        });
        orderGoodAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Navigation.goPacketDetail((FragmentActivity) mContext,item.getOrder_id());
            }
        });
    }

    public interface OnItemClickLinstener {
        void onConfirm(int position);

        void onCancel(int position);
    }

    public void setOn0ItemClickLinstener(OnItemClickLinstener onItemClickLinstener) {
        mOnItemClickLinstener = onItemClickLinstener;
    }
}
